package com.device.entity;

import javax.persistence.*;
import java.util.UUID;

/**
 * 分设备信息
 */
@Entity
@Table(name = "sub_devices")
public class SubDevice {
    
    @Id
    @Column(name = "id")
    private UUID id;
    
    @Column(name = "main_device_imei", nullable = false)
    private String mainDeviceImei;  // 关联主设备的IMEI
    
    @Column(name = "sub_device_id", nullable = false)
    private String subDeviceId;     // 分设备ID
    
    @Column(name = "device_name")
    private String deviceName;      // 设备名称
    
    @Column(name = "device_model", nullable = false)
    private String deviceModel;     // 设备型号
    
    @Column(name = "response_timeout", nullable = false)
    private Integer responseTimeout; // 轮询应答超时时间ms
    
    @Column(name = "polling_interval", nullable = false)
    private Integer pollingInterval; // 轮询周期时间ms
    
    @Column(name = "created_time")
    private Long createdTime;
    
    @Column(name = "updated_time")
    private Long updatedTime;
    
    // Constructors
    public SubDevice() {}
    
    public SubDevice(String mainDeviceImei, String subDeviceId, String deviceName, String deviceModel, 
                    Integer responseTimeout, Integer pollingInterval) {
        this.id = UUID.randomUUID();
        this.mainDeviceImei = mainDeviceImei;
        this.subDeviceId = subDeviceId;
        this.deviceName = deviceName;
        this.deviceModel = deviceModel;
        this.responseTimeout = responseTimeout != null ? responseTimeout : 500;
        this.pollingInterval = pollingInterval != null ? pollingInterval : 5000;
        this.createdTime = System.currentTimeMillis();
        this.updatedTime = System.currentTimeMillis();
    }

    // Getters and Setters
    public UUID getId() {
        return id;
    }

    public void setId(UUID id) {
        this.id = id;
    }

    public String getMainDeviceImei() {
        return mainDeviceImei;
    }

    public void setMainDeviceImei(String mainDeviceImei) {
        this.mainDeviceImei = mainDeviceImei;
    }

    public String getSubDeviceId() {
        return subDeviceId;
    }

    public void setSubDeviceId(String subDeviceId) {
        this.subDeviceId = subDeviceId;
    }
    
    public String getDeviceName() {
        return deviceName;
    }
    
    public void setDeviceName(String deviceName) {
        this.deviceName = deviceName;
    }

    public String getDeviceModel() {
        return deviceModel;
    }

    public void setDeviceModel(String deviceModel) {
        this.deviceModel = deviceModel;
    }

    public Integer getResponseTimeout() {
        return responseTimeout;
    }

    public void setResponseTimeout(Integer responseTimeout) {
        this.responseTimeout = responseTimeout;
    }

    public Integer getPollingInterval() {
        return pollingInterval;
    }

    public void setPollingInterval(Integer pollingInterval) {
        this.pollingInterval = pollingInterval;
    }

    public Long getCreatedTime() {
        return createdTime;
    }

    public void setCreatedTime(Long createdTime) {
        this.createdTime = createdTime;
    }

    public Long getUpdatedTime() {
        return updatedTime;
    }

    public void setUpdatedTime(Long updatedTime) {
        this.updatedTime = updatedTime;
    }

    @Override
    public String toString() {
        return "SubDevice{" +
                "id=" + id +
                ", mainDeviceImei='" + mainDeviceImei + '\'' +
                ", subDeviceId='" + subDeviceId + '\'' +
                ", deviceName='" + deviceName + '\'' +
                ", deviceModel='" + deviceModel + '\'' +
                ", responseTimeout=" + responseTimeout +
                ", pollingInterval=" + pollingInterval +
                ", createdTime=" + createdTime +
                ", updatedTime=" + updatedTime +
                '}';
    }
}